<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD><TITLE>Tcl_ParseCommand manual page - Tcl Library Procedures</TITLE>
<link rel="stylesheet" href="../docs.css" type="text/css" media="all">
</HEAD>
<BODY><H2><a href="../contents.htm">Tcl8.6.11/Tk8.6.11 Documentation</a> <small>&gt;</small> <a href="contents.htm">Tcl C API</a> <small>&gt;</small> ParseCmd</H2>
<H3><A HREF="../UserCmd/contents.htm">Tcl/Tk Applications</A> | <A HREF="../TclCmd/contents.htm">Tcl Commands</A> | <A HREF="../TkCmd/contents.htm">Tk Commands</A> | <A HREF="../ItclCmd/contents.htm">[incr Tcl] Package Commands</A> | <A HREF="../SqliteCmd/contents.htm">SQLite3 Package Commands</A> | <A HREF="../TdbcCmd/contents.htm">TDBC Package Commands</A> | <A HREF="../TdbcmysqlCmd/contents.htm">tdbc::mysql Package Commands</A> | <A HREF="../TdbcodbcCmd/contents.htm">tdbc::odbc Package Commands</A> | <A HREF="../TdbcpostgresCmd/contents.htm">tdbc::postgres Package Commands</A> | <A HREF="../TdbcsqliteCmd/contents.htm">tdbc::sqlite3 Package Commands</A> | <A HREF="../ThreadCmd/contents.htm">Thread Package Commands</A> | <A HREF="../TclLib/contents.htm">Tcl C API</A> | <A HREF="../TkLib/contents.htm">Tk C API</A> | <A HREF="../ItclLib/contents.htm">[incr Tcl] Package C API</A> | <A HREF="../TdbcLib/contents.htm">TDBC Package C API</A></H3>
<DL>
<DD><A HREF="ParseCmd.htm#M2" NAME="L609">NAME</A>
<DL><DD>Tcl_ParseCommand, Tcl_ParseExpr, Tcl_ParseBraces, Tcl_ParseQuotedString, Tcl_ParseVarName, Tcl_ParseVar, Tcl_FreeParse, Tcl_EvalTokens, Tcl_EvalTokensStandard &mdash; parse Tcl scripts and expressions</DD></DL>
<DD><A HREF="ParseCmd.htm#M3" NAME="L610">SYNOPSIS</A>
<DL>
<DD><B>#include &lt;tcl.h&gt;</B>
<DD>int
<DD><B>Tcl_ParseCommand</B>(<I>interp, start, numBytes, nested, parsePtr</I>)
<DD>int
<DD><B>Tcl_ParseExpr</B>(<I>interp, start, numBytes, parsePtr</I>)
<DD>int
<DD><B>Tcl_ParseBraces</B>(<I>interp, start, numBytes, parsePtr, append, termPtr</I>)
<DD>int
<DD><B>Tcl_ParseQuotedString</B>(<I>interp, start, numBytes, parsePtr, append, termPtr</I>)
<DD>int
<DD><B>Tcl_ParseVarName</B>(<I>interp, start, numBytes, parsePtr, append</I>)
<DD>const char *
<DD><B>Tcl_ParseVar</B>(<I>interp, start, termPtr</I>)
<DD><B>Tcl_FreeParse</B>(<I>usedParsePtr</I>)
<DD>Tcl_Obj *
<DD><B>Tcl_EvalTokens</B>(<I>interp, tokenPtr, numTokens</I>)
<DD>int
<DD><B>Tcl_EvalTokensStandard</B>(<I>interp, tokenPtr, numTokens</I>)
</DL>
<DD><A HREF="ParseCmd.htm#M4" NAME="L611">ARGUMENTS</A>
<DL class="arguments">
</DL>
<DD><A HREF="ParseCmd.htm#M5" NAME="L612">DESCRIPTION</A>
<DD><A HREF="ParseCmd.htm#M6" NAME="L613">TCL_PARSE STRUCTURE</A>
<DL class="tcl_parse structure">
<DD><A HREF="ParseCmd.htm#M7" NAME="L614"><B>TCL_TOKEN_WORD</B></A>
<DD><A HREF="ParseCmd.htm#M8" NAME="L615"><B>TCL_TOKEN_SIMPLE_WORD</B></A>
<DD><A HREF="ParseCmd.htm#M9" NAME="L616"><B>TCL_TOKEN_EXPAND_WORD</B></A>
<DD><A HREF="ParseCmd.htm#M10" NAME="L617"><B>TCL_TOKEN_TEXT</B></A>
<DD><A HREF="ParseCmd.htm#M11" NAME="L618"><B>TCL_TOKEN_BS</B></A>
<DD><A HREF="ParseCmd.htm#M12" NAME="L619"><B>TCL_TOKEN_COMMAND</B></A>
<DD><A HREF="ParseCmd.htm#M13" NAME="L620"><B>TCL_TOKEN_VARIABLE</B></A>
<DD><A HREF="ParseCmd.htm#M14" NAME="L621"><B>TCL_TOKEN_SUB_EXPR</B></A>
<DD><A HREF="ParseCmd.htm#M15" NAME="L622"><B>TCL_TOKEN_OPERATOR</B></A>
</DL>
<DD><A HREF="ParseCmd.htm#M16" NAME="L623">KEYWORDS</A>
</DL>
<H3><A NAME="M2">NAME</A></H3>
Tcl_ParseCommand, Tcl_ParseExpr, Tcl_ParseBraces, Tcl_ParseQuotedString, Tcl_ParseVarName, Tcl_ParseVar, Tcl_FreeParse, Tcl_EvalTokens, Tcl_EvalTokensStandard &mdash; parse Tcl scripts and expressions
<H3><A NAME="M3">SYNOPSIS</A></H3>
<B>#include &lt;tcl.h&gt;</B><BR>
int<BR>
<B>Tcl_ParseCommand</B>(<I>interp, start, numBytes, nested, parsePtr</I>)<BR>
int<BR>
<B>Tcl_ParseExpr</B>(<I>interp, start, numBytes, parsePtr</I>)<BR>
int<BR>
<B>Tcl_ParseBraces</B>(<I>interp, start, numBytes, parsePtr, append, termPtr</I>)<BR>
int<BR>
<B>Tcl_ParseQuotedString</B>(<I>interp, start, numBytes, parsePtr, append, termPtr</I>)<BR>
int<BR>
<B>Tcl_ParseVarName</B>(<I>interp, start, numBytes, parsePtr, append</I>)<BR>
const char *<BR>
<B>Tcl_ParseVar</B>(<I>interp, start, termPtr</I>)<BR>
<B>Tcl_FreeParse</B>(<I>usedParsePtr</I>)<BR>
<A HREF="../TclLib/Object.htm">Tcl_Obj</A> *<BR>
<B>Tcl_EvalTokens</B>(<I>interp, tokenPtr, numTokens</I>)<BR>
int<BR>
<B>Tcl_EvalTokensStandard</B>(<I>interp, tokenPtr, numTokens</I>)<BR>
<H3><A NAME="M4">ARGUMENTS</A></H3>
<DL class="arguments">
<DT><A HREF="../TclLib/Interp.htm">Tcl_Interp</A> <B>*interp</B> (out)<DD>
For procedures other than <B>Tcl_FreeParse</B>, <B>Tcl_EvalTokens</B>
and <B>Tcl_EvalTokensStandard</B>, used only for error reporting;
if NULL, then no error messages are left after errors.
For <B>Tcl_EvalTokens</B> and <B>Tcl_EvalTokensStandard</B>,
determines the context for evaluating the
script and also is used for error reporting; must not be NULL.
<P><DT>const char <B>*start</B> (in)<DD>
Pointer to first character in string to parse.
<P><DT>int <B>numBytes</B> (in)<DD>
Number of bytes in string to parse, not including any terminating null
character.  If less than 0 then the script consists of all characters
following <I>start</I> up to the first null character.
<P><DT>int <B>nested</B> (in)<DD>
Non-zero means that the script is part of a command substitution so an
unquoted close bracket should be treated as a command terminator.  If zero,
close brackets have no special meaning.
<P><DT>int <B><A HREF="../TclCmd/append.htm">append</A></B> (in)<DD>
Non-zero means that <I>*parsePtr</I> already contains valid tokens; the new
tokens should be appended to those already present.  Zero means that
<I>*parsePtr</I> is uninitialized; any information in it is ignored.
This argument is normally 0.
<P><DT>Tcl_Parse <B>*parsePtr</B> (out)<DD>
Points to structure to fill in with information about the parsed
command, expression, variable name, etc.
Any previous information in this structure
is ignored, unless <I>append</I> is non-zero in a call to
<B>Tcl_ParseBraces</B>, <B>Tcl_ParseQuotedString</B>,
or <B>Tcl_ParseVarName</B>.
<P><DT>const char <B>**termPtr</B> (out)<DD>
If not NULL, points to a location where
<B>Tcl_ParseBraces</B>, <B>Tcl_ParseQuotedString</B>, and
<B>Tcl_ParseVar</B> will store a pointer to the character
just after the terminating character (the close-brace, the last
character of the variable name, or the close-quote (respectively))
if the parse was successful.
<P><DT>Tcl_Parse <B>*usedParsePtr</B> (in)<DD>
Points to structure that was filled in by a previous call to
<B>Tcl_ParseCommand</B>, <B>Tcl_ParseExpr</B>, <B>Tcl_ParseVarName</B>, etc.
<P></DL>
<H3><A NAME="M5">DESCRIPTION</A></H3>
These procedures parse Tcl commands or portions of Tcl commands such as
expressions or references to variables.
Each procedure takes a pointer to a script (or portion thereof)
and fills in the structure pointed to by <I>parsePtr</I>
with a collection of tokens describing the information that was parsed.
The procedures normally return <B><A HREF="../TclCmd/catch.htm">TCL_OK</A></B>.
However, if an error occurs then they return <B><A HREF="../TclCmd/catch.htm">TCL_ERROR</A></B>,
leave an error message in <I>interp</I>'s result
(if <I>interp</I> is not NULL),
and leave nothing in <I>parsePtr</I>.
<P>
<B>Tcl_ParseCommand</B> is a procedure that parses Tcl
scripts.  Given a pointer to a script, it
parses the first command from the script.  If the command was parsed
successfully, <B>Tcl_ParseCommand</B> returns <B><A HREF="../TclCmd/catch.htm">TCL_OK</A></B> and fills in the
structure pointed to by <I>parsePtr</I> with information about the
structure of the command (see below for details).
If an error occurred in parsing the command then
<B><A HREF="../TclCmd/catch.htm">TCL_ERROR</A></B> is returned, an error message is left in <I>interp</I>'s
result, and no information is left at <I>*parsePtr</I>.
<P>
<B>Tcl_ParseExpr</B> parses Tcl expressions.
Given a pointer to a script containing an expression,
<B>Tcl_ParseExpr</B> parses the expression.
If the expression was parsed successfully,
<B>Tcl_ParseExpr</B> returns <B><A HREF="../TclCmd/catch.htm">TCL_OK</A></B> and fills in the
structure pointed to by <I>parsePtr</I> with information about the
structure of the expression (see below for details).
If an error occurred in parsing the command then
<B><A HREF="../TclCmd/catch.htm">TCL_ERROR</A></B> is returned, an error message is left in <I>interp</I>'s
result, and no information is left at <I>*parsePtr</I>.
<P>
<B>Tcl_ParseBraces</B> parses a string or command argument
enclosed in braces such as
<B>{hello}</B> or <B>{string &#92;t with &#92;t tabs}</B>
from the beginning of its argument <I>start</I>.
The first character of <I>start</I> must be <B>{</B>.
If the braced string was parsed successfully,
<B>Tcl_ParseBraces</B> returns <B><A HREF="../TclCmd/catch.htm">TCL_OK</A></B>,
fills in the structure pointed to by <I>parsePtr</I>
with information about the structure of the string
(see below for details),
and stores a pointer to the character just after the terminating <B>}</B>
in the location given by <I>*termPtr</I>.
If an error occurs while parsing the string
then <B><A HREF="../TclCmd/catch.htm">TCL_ERROR</A></B> is returned,
an error message is left in <I>interp</I>'s result,
and no information is left at <I>*parsePtr</I> or <I>*termPtr</I>.
<P>
<B>Tcl_ParseQuotedString</B> parses a double-quoted string such as
<B>&quot;sum is [expr {$a+$b}]&quot;</B>
from the beginning of the argument <I>start</I>.
The first character of <I>start</I> must be <B>&#34;</B>.
If the double-quoted string was parsed successfully,
<B>Tcl_ParseQuotedString</B> returns <B><A HREF="../TclCmd/catch.htm">TCL_OK</A></B>,
fills in the structure pointed to by <I>parsePtr</I>
with information about the structure of the string
(see below for details),
and stores a pointer to the character just after the terminating <B>&#34;</B>
in the location given by <I>*termPtr</I>.
If an error occurs while parsing the string
then <B><A HREF="../TclCmd/catch.htm">TCL_ERROR</A></B> is returned,
an error message is left in <I>interp</I>'s result,
and no information is left at <I>*parsePtr</I> or <I>*termPtr</I>.
<P>
<B>Tcl_ParseVarName</B> parses a Tcl variable reference such as
<B>$abc</B> or <B>$x([expr {$index + 1}])</B> from the beginning of its
<I>start</I> argument.
The first character of <I>start</I> must be <B>$</B>.
If a variable name was parsed successfully, <B>Tcl_ParseVarName</B>
returns <B><A HREF="../TclCmd/catch.htm">TCL_OK</A></B> and fills in the structure pointed to by
<I>parsePtr</I> with information about the structure of the variable name
(see below for details).  If an error
occurs while parsing the command then <B><A HREF="../TclCmd/catch.htm">TCL_ERROR</A></B> is returned, an
error message is left in <I>interp</I>'s result (if <I>interp</I> is not
NULL), and no information is left at <I>*parsePtr</I>.
<P>
<B>Tcl_ParseVar</B> parse a Tcl variable reference such as <B>$abc</B>
or <B>$x([expr {$index + 1}])</B> from the beginning of its <I>start</I>
argument.  The first character of <I>start</I> must be <B>$</B>.  If
the variable name is parsed successfully, <B>Tcl_ParseVar</B> returns a
pointer to the string value of the variable.  If an error occurs while
parsing, then NULL is returned and an error message is left in
<I>interp</I>'s result.
<P>
The information left at <I>*parsePtr</I>
by <B>Tcl_ParseCommand</B>, <B>Tcl_ParseExpr</B>, <B>Tcl_ParseBraces</B>,
<B>Tcl_ParseQuotedString</B>, and <B>Tcl_ParseVarName</B>
may include dynamically allocated memory.
If these five parsing procedures return <B><A HREF="../TclCmd/catch.htm">TCL_OK</A></B>
then the caller must invoke <B>Tcl_FreeParse</B> to release
the storage at <I>*parsePtr</I>.
These procedures ignore any existing information in
<I>*parsePtr</I> (unless <I>append</I> is non-zero),
so if repeated calls are being made to any of them
then <B>Tcl_FreeParse</B> must be invoked once after each call.
<P>
<B>Tcl_EvalTokensStandard</B> evaluates a sequence of parse tokens from
a Tcl_Parse structure.  The tokens typically consist
of all the tokens in a word or all the tokens that make up the index for
a reference to an array variable.  <B>Tcl_EvalTokensStandard</B> performs the
substitutions requested by the tokens and concatenates the
resulting values.
The return value from <B>Tcl_EvalTokensStandard</B> is a Tcl completion
code with one of the values <B><A HREF="../TclCmd/catch.htm">TCL_OK</A></B>, <B><A HREF="../TclCmd/catch.htm">TCL_ERROR</A></B>,
<B><A HREF="../TclCmd/catch.htm">TCL_RETURN</A></B>, <B><A HREF="../TclCmd/catch.htm">TCL_BREAK</A></B>, or <B><A HREF="../TclCmd/catch.htm">TCL_CONTINUE</A></B>, or possibly
some other integer value originating in an extension.
In addition, a result value or error message is left in <I>interp</I>'s
result; it can be retrieved using <B><A HREF="../TclLib/SetResult.htm">Tcl_GetObjResult</A></B>.
<P>
<B>Tcl_EvalTokens</B> differs from <B>Tcl_EvalTokensStandard</B> only in
the return convention used: it returns the result in a new <A HREF="../TclLib/Object.htm">Tcl_Obj</A>.
The reference count of the value returned as result has been
incremented, so the caller must
invoke <B><A HREF="../TclLib/Object.htm">Tcl_DecrRefCount</A></B> when it is finished with the value.
If an error or other exception occurs while evaluating the tokens
(such as a reference to a non-existent variable) then the return value
is NULL and an error message is left in <I>interp</I>'s result. The use
of <B>Tcl_EvalTokens</B> is deprecated.
<H3><A NAME="M6">TCL_PARSE STRUCTURE</A></H3>
<B>Tcl_ParseCommand</B>, <B>Tcl_ParseExpr</B>, <B>Tcl_ParseBraces</B>,
<B>Tcl_ParseQuotedString</B>, and <B>Tcl_ParseVarName</B>
return parse information in two data structures, Tcl_Parse and Tcl_Token:
<P>
<PRE>typedef struct Tcl_Parse {
    const char *<I>commentStart</I>;
    int <I>commentSize</I>;
    const char *<I>commandStart</I>;
    int <I>commandSize</I>;
    int <I>numWords</I>;
    Tcl_Token *<I>tokenPtr</I>;
    int <I>numTokens</I>;
    ...
} <B>Tcl_Parse</B>;

typedef struct Tcl_Token {
    int <I>type</I>;
    const char *<I>start</I>;
    int <I>size</I>;
    int <I>numComponents</I>;
} <B>Tcl_Token</B>;</PRE>
<P>
The first five fields of a Tcl_Parse structure
are filled in only by <B>Tcl_ParseCommand</B>.
These fields are not used by the other parsing procedures.
<P>
<B>Tcl_ParseCommand</B> fills in a Tcl_Parse structure
with information that describes one Tcl command and any comments that
precede the command.
If there are comments,
the <I>commentStart</I> field points to the <B>#</B> character that begins
the first comment and <I>commentSize</I> indicates the number of bytes
in all of the comments preceding the command, including the newline
character that terminates the last comment.
If the command is not preceded by any comments, <I>commentSize</I> is 0.
<B>Tcl_ParseCommand</B> also sets the <I>commandStart</I> field
to point to the first character of the first
word in the command (skipping any comments and leading space) and
<I>commandSize</I> gives the total number of bytes in the command,
including the character pointed to by <I>commandStart</I> up to and
including the newline, close bracket, or semicolon character that
terminates the command.  The <I>numWords</I> field gives the
total number of words in the command.
<P>
All parsing procedures set the remaining fields,
<I>tokenPtr</I> and <I>numTokens</I>.
The <I>tokenPtr</I> field points to the first in an array of Tcl_Token
structures that describe the components of the entity being parsed.
The <I>numTokens</I> field gives the total number of tokens
present in the array.
Each token contains four fields.
The <I>type</I> field selects one of several token types
that are described below.  The <I>start</I> field
points to the first character in the token and the <I>size</I> field
gives the total number of characters in the token.  Some token types,
such as <B>TCL_TOKEN_WORD</B> and <B>TCL_TOKEN_VARIABLE</B>, consist of
several component tokens, which immediately follow the parent token;
the <I>numComponents</I> field describes how many of these there are.
The <I>type</I> field has one of the following values:
<P>
<DL class="tcl_parse structure">
<DT><A NAME="M7"><B>TCL_TOKEN_WORD</B></A><DD>
This token ordinarily describes one word of a command
but it may also describe a quoted or braced string in an expression.
The token describes a component of the script that is
the result of concatenating together a sequence of subcomponents,
each described by a separate subtoken.
The token starts with the first non-blank
character of the component (which may be a double-quote or open brace)
and includes all characters in the component up to but not including the
space, semicolon, close bracket, close quote, or close brace that
terminates the component.  The <I>numComponents</I> field counts the total
number of sub-tokens that make up the word, including sub-tokens
of <B>TCL_TOKEN_VARIABLE</B> and <B>TCL_TOKEN_BS</B> tokens.
<P><DT><A NAME="M8"><B>TCL_TOKEN_SIMPLE_WORD</B></A><DD>
This token has the same meaning as <B>TCL_TOKEN_WORD</B>, except that
the word is guaranteed to consist of a single <B>TCL_TOKEN_TEXT</B>
sub-token.  The <I>numComponents</I> field is always 1.
<P><DT><A NAME="M9"><B>TCL_TOKEN_EXPAND_WORD</B></A><DD>
This token has the same meaning as <B>TCL_TOKEN_WORD</B>, except that
the command parser notes this word began with the expansion
prefix <B>{*}</B>, indicating that after substitution,
the list value of this word should be expanded to form multiple
arguments in command evaluation.  This
token type can only be created by Tcl_ParseCommand.
<P><DT><A NAME="M10"><B>TCL_TOKEN_TEXT</B></A><DD>
The token describes a range of literal text that is part of a word.
The <I>numComponents</I> field is always 0.
<P><DT><A NAME="M11"><B>TCL_TOKEN_BS</B></A><DD>
The token describes a backslash sequence such as <B>&#92;n</B> or <B>&#92;0xA3</B>.
The <I>numComponents</I> field is always 0.
<P><DT><A NAME="M12"><B>TCL_TOKEN_COMMAND</B></A><DD>
The token describes a command whose result must be substituted into
the word.  The token includes the square brackets that surround the
command.  The <I>numComponents</I> field is always 0 (the nested command
is not parsed; call <B>Tcl_ParseCommand</B> recursively if you want to
see its tokens).
<P><DT><A NAME="M13"><B>TCL_TOKEN_VARIABLE</B></A><DD>
The token describes a variable substitution, including the
<B>$</B>, variable name, and array index (if there is one) up through the
close parenthesis that terminates the index.  This token is followed
by one or more additional tokens that describe the variable name and
array index.  If <I>numComponents</I>  is 1 then the variable is a
scalar and the next token is a <B>TCL_TOKEN_TEXT</B> token that gives the
variable name.  If <I>numComponents</I> is greater than 1 then the
variable is an array: the first sub-token is a <B>TCL_TOKEN_TEXT</B>
token giving the array name and the remaining sub-tokens are
<B>TCL_TOKEN_TEXT</B>, <B>TCL_TOKEN_BS</B>, <B>TCL_TOKEN_COMMAND</B>, and
<B>TCL_TOKEN_VARIABLE</B> tokens that must be concatenated to produce the
array index. The <I>numComponents</I> field includes nested sub-tokens
that are part of <B>TCL_TOKEN_VARIABLE</B> tokens in the array index.
<P><DT><A NAME="M14"><B>TCL_TOKEN_SUB_EXPR</B></A><DD>
The token describes one subexpression of an expression
(or an entire expression).
A subexpression may consist of a value
such as an integer literal, variable substitution,
or parenthesized subexpression;
it may also consist of an operator and its operands.
The token starts with the first non-blank character of the subexpression
up to but not including the space, brace, close-paren, or bracket
that terminates the subexpression.
This token is followed by one or more additional tokens
that describe the subexpression.
If the first sub-token after the <B>TCL_TOKEN_SUB_EXPR</B> token
is a <B>TCL_TOKEN_OPERATOR</B> token,
the subexpression consists of an operator and its token operands.
If the operator has no operands, the subexpression consists of
just the <B>TCL_TOKEN_OPERATOR</B> token.
Each operand is described by a <B>TCL_TOKEN_SUB_EXPR</B> token.
Otherwise, the subexpression is a value described by
one of the token types <B>TCL_TOKEN_WORD</B>, <B>TCL_TOKEN_TEXT</B>,
<B>TCL_TOKEN_BS</B>, <B>TCL_TOKEN_COMMAND</B>,
<B>TCL_TOKEN_VARIABLE</B>, and <B>TCL_TOKEN_SUB_EXPR</B>.
The <I>numComponents</I> field
counts the total number of sub-tokens that make up the subexpression;
this includes the sub-tokens for any nested <B>TCL_TOKEN_SUB_EXPR</B> tokens.
<P><DT><A NAME="M15"><B>TCL_TOKEN_OPERATOR</B></A><DD>
The token describes one operator of an expression
such as <B>&amp;&amp;</B> or <B>hypot</B>.
A <B>TCL_TOKEN_OPERATOR</B> token is always preceded by a
<B>TCL_TOKEN_SUB_EXPR</B> token
that describes the operator and its operands;
the <B>TCL_TOKEN_SUB_EXPR</B> token's <I>numComponents</I> field
can be used to determine the number of operands.
A binary operator such as <B>*</B>
is followed by two <B>TCL_TOKEN_SUB_EXPR</B> tokens
that describe its operands.
A unary operator like <B>-</B>
is followed by a single <B>TCL_TOKEN_SUB_EXPR</B> token
for its operand.
If the operator is a math function such as <B>log10</B>,
the <B>TCL_TOKEN_OPERATOR</B> token will give its name and
the following <B>TCL_TOKEN_SUB_EXPR</B> tokens will describe
its operands;
if there are no operands (as with <B>rand</B>),
no <B>TCL_TOKEN_SUB_EXPR</B> tokens follow.
There is one trinary operator, <B>?</B>,
that appears in if-then-else subexpressions
such as <I>x</I><B>?</B><I>y</I><B>:</B><I>z</I>;
in this case, the <B>?</B> <B>TCL_TOKEN_OPERATOR</B> token
is followed by three <B>TCL_TOKEN_SUB_EXPR</B> tokens for the operands
<I>x</I>, <I>y</I>, and <I>z</I>.
The <I>numComponents</I> field for a <B>TCL_TOKEN_OPERATOR</B> token
is always 0.
<P></DL>
<P>
After <B>Tcl_ParseCommand</B> returns, the first token pointed to by
the <I>tokenPtr</I> field of the
Tcl_Parse structure always has type <B>TCL_TOKEN_WORD</B> or
<B>TCL_TOKEN_SIMPLE_WORD</B> or <B>TCL_TOKEN_EXPAND_WORD</B>.
It is followed by the sub-tokens
that must be concatenated to produce the value of that word.
The next token is the <B>TCL_TOKEN_WORD</B> or <B>TCL_TOKEN_SIMPLE_WORD</B>
of <B>TCL_TOKEN_EXPAND_WORD</B> token for the second word,
followed by sub-tokens for that
word, and so on until all <I>numWords</I> have been accounted
for.
<P>
After <B>Tcl_ParseExpr</B> returns, the first token pointed to by
the <I>tokenPtr</I> field of the
Tcl_Parse structure always has type <B>TCL_TOKEN_SUB_EXPR</B>.
It is followed by the sub-tokens that must be evaluated
to produce the value of the expression.
Only the token information in the Tcl_Parse structure
is modified: the <I>commentStart</I>, <I>commentSize</I>,
<I>commandStart</I>, and <I>commandSize</I> fields are not modified
by <B>Tcl_ParseExpr</B>.
<P>
After <B>Tcl_ParseBraces</B> returns,
the array of tokens pointed to by the <I>tokenPtr</I> field of the
Tcl_Parse structure will contain a single <B>TCL_TOKEN_TEXT</B> token
if the braced string does not contain any backslash-newlines.
If the string does contain backslash-newlines,
the array of tokens will contain one or more
<B>TCL_TOKEN_TEXT</B> or <B>TCL_TOKEN_BS</B> sub-tokens
that must be concatenated to produce the value of the string.
If the braced string was just <B>{}</B>
(that is, the string was empty),
the single <B>TCL_TOKEN_TEXT</B> token will have a <I>size</I> field
containing zero;
this ensures that at least one token appears
to describe the braced string.
Only the token information in the Tcl_Parse structure
is modified: the <I>commentStart</I>, <I>commentSize</I>,
<I>commandStart</I>, and <I>commandSize</I> fields are not modified
by <B>Tcl_ParseBraces</B>.
<P>
After <B>Tcl_ParseQuotedString</B> returns,
the array of tokens pointed to by the <I>tokenPtr</I> field of the
Tcl_Parse structure depends on the contents of the quoted string.
It will consist of one or more <B>TCL_TOKEN_TEXT</B>, <B>TCL_TOKEN_BS</B>,
<B>TCL_TOKEN_COMMAND</B>, and <B>TCL_TOKEN_VARIABLE</B> sub-tokens.
The array always contains at least one token;
for example, if the argument <I>start</I> is empty,
the array returned consists of a single <B>TCL_TOKEN_TEXT</B> token
with a zero <I>size</I> field.
Only the token information in the Tcl_Parse structure
is modified: the <I>commentStart</I>, <I>commentSize</I>,
<I>commandStart</I>, and <I>commandSize</I> fields are not modified.
<P>
After <B>Tcl_ParseVarName</B> returns, the first token pointed to by
the <I>tokenPtr</I> field of the
Tcl_Parse structure always has type <B>TCL_TOKEN_VARIABLE</B>.  It
is followed by the sub-tokens that make up the variable name as
described above.  The total length of the variable name is
contained in the <I>size</I> field of the first token.
As in <B>Tcl_ParseExpr</B>,
only the token information in the Tcl_Parse structure
is modified by <B>Tcl_ParseVarName</B>:
the <I>commentStart</I>, <I>commentSize</I>,
<I>commandStart</I>, and <I>commandSize</I> fields are not modified.
<P>
All of the character pointers in the
Tcl_Parse and Tcl_Token structures refer
to characters in the <I>start</I> argument passed to
<B>Tcl_ParseCommand</B>, <B>Tcl_ParseExpr</B>, <B>Tcl_ParseBraces</B>,
<B>Tcl_ParseQuotedString</B>, and <B>Tcl_ParseVarName</B>.
<P>
There are additional fields in the Tcl_Parse structure after the
<I>numTokens</I> field, but these are for the private use of
<B>Tcl_ParseCommand</B>, <B>Tcl_ParseExpr</B>, <B>Tcl_ParseBraces</B>,
<B>Tcl_ParseQuotedString</B>, and <B>Tcl_ParseVarName</B>; they should not be
referenced by code outside of these procedures.
<H3><A NAME="M16">KEYWORDS</A></H3>
<A href="../Keywords/B.htm#backslash substitution">backslash substitution</A>, <A href="../Keywords/B.htm#braces">braces</A>, <A href="../Keywords/C.htm#command">command</A>, <A href="../Keywords/E.htm#expression">expression</A>, <A href="../Keywords/P.htm#parse">parse</A>, <A href="../Keywords/T.htm#token">token</A>, <A href="../Keywords/V.htm#variable substitution">variable substitution</A>
<div class="copy">Copyright &copy; 1997 Sun Microsystems, Inc.
</div>
</BODY></HTML>
